package com.anxin.act.listener;

import com.anxin.act.model.service.WfActApproverService;
import com.anxin.act.utils.ActUtils;
import com.anxin.common.utils.StringUtils;
import com.anxin.sys.sql.dao.SqlDao;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.ExecutionListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;

import java.util.Map;
@Configuration
public class DataUpdateListener  implements ExecutionListener{
    @Autowired
    private WfActApproverService wfActApproverService;
    @Autowired
    private SqlDao sqlDao;

    @Override
    public void notify(DelegateExecution execution) throws Exception {

    }

    /**
     * 更新项目数据
     * @param execution 流程实例
     * @param field 字段名称
     * @param value 字段值
     */
    public void updateDealField(DelegateExecution execution, String field, String value) {
        Map<String, String> dataTableAndDataId = ActUtils.getDataTableAndDataId(execution.getProcessInstanceId());
        // 业务表名
        String actDataTable = dataTableAndDataId.get("actDataTable");
        // 业务ID
        String actDataId = dataTableAndDataId.get("actDataId");

        String dealId = wfActApproverService.getDealId(actDataTable, actDataId);

        sqlDao.updateDealField(StringUtils.symbolHandler(dealId), StringUtils.symbolHandler(field), StringUtils.symbolHandler(value));

    }
}
